What's wrong with this picture?

I have a column that I've converted from DXL to text.
I want to copy it to a boolean column.

Why is the if statement an error?
Thanks.


Object o

for o in current Module do
{
if (o."DXL for setIsLegacy" == "True")
{
o."isLegacy" = "True"
}
}// end for o in current Module
tlwtheq - Thu Jun 16 12:31:23 EDT 2011

Re: What's wrong with this picture?
llandale - Thu Jun 16 13:25:59 EDT 2011

The construction <o.NameAttr> returns a variable of type "Attr__" (aka "attrRef" in the manual), it does NOT retrieve the attribute value. To retrieve the attr value you must:
a) Use that as the right side of an assignment: ... S = o."DXL for setIsLegacy"
b) Concatenate it with a string: ... o."DXL for setIsLegacy" ""

So that line becomes:

if (o."DXL for setIsLegacy" "" == "True")

Now it indeed says that is sub-section "Concatenation (attribute)" and "Assignment (from attribute)", and if you read each and every word of the manual and remember exactly what was said, you will (of course) notice that it does NOT say anything about comparing an "attrRef" with a string, as in <o.NameAttr == "S">. That means you cannot do it.

OK, is usually means you cannot do it but I digress.

I can say without hesitation that 99% of all DXL programers have done what you did since the DXL manual is rather confusing, even if it is indeed technically correct.

  • Louie

Now some nit-picks:

As for your code, I notice that when "setLegacy" is false that you leave "isLegacy" alone, which means it could have retained a true value.

I notice that your question suggests taht "isLegacy" is an attribute of type Boolean. If so, this may work better:

o."isLegacy" = true

You should also please avoid using the word "Column" and in this case surely you mean "Attribute" or "Object Attribute" or "Object Attribute Value". A "Column" is something you see in a view, and while it usually contains a specific "Attribute" it can contain other things. Perhaps your first two lines really are:

I had a Layout Column that I converted to an Attr-DXL of type Text.
I want to copy that text attribute to a boolean attribute for all objects.

Re: What's wrong with this picture?
tlwtheq - Thu Jun 16 13:32:10 EDT 2011

llandale - Thu Jun 16 13:25:59 EDT 2011
The construction <o.NameAttr> returns a variable of type "Attr__" (aka "attrRef" in the manual), it does NOT retrieve the attribute value. To retrieve the attr value you must:
a) Use that as the right side of an assignment: ... S = o."DXL for setIsLegacy"
b) Concatenate it with a string: ... o."DXL for setIsLegacy" ""

So that line becomes:

if (o."DXL for setIsLegacy" "" == "True")

Now it indeed says that is sub-section "Concatenation (attribute)" and "Assignment (from attribute)", and if you read each and every word of the manual and remember exactly what was said, you will (of course) notice that it does NOT say anything about comparing an "attrRef" with a string, as in <o.NameAttr == "S">. That means you cannot do it.

OK, is usually means you cannot do it but I digress.

I can say without hesitation that 99% of all DXL programers have done what you did since the DXL manual is rather confusing, even if it is indeed technically correct.

  • Louie

Now some nit-picks:

As for your code, I notice that when "setLegacy" is false that you leave "isLegacy" alone, which means it could have retained a true value.

I notice that your question suggests taht "isLegacy" is an attribute of type Boolean. If so, this may work better:

o."isLegacy" = true

You should also please avoid using the word "Column" and in this case surely you mean "Attribute" or "Object Attribute" or "Object Attribute Value". A "Column" is something you see in a view, and while it usually contains a specific "Attribute" it can contain other things. Perhaps your first two lines really are:

I had a Layout Column that I converted to an Attr-DXL of type Text.
I want to copy that text attribute to a boolean attribute for all objects.

Thanks Louie. No errors, but it doesn't do anything either. Ideas?

Object o
for o in current Module do
{
if (o."DXL for setIsLegacy" "" == "True")
{
o."isLegacy" = "true"
}
}// end for o in current Module

Re: What's wrong with this picture?
tlwtheq - Thu Jun 16 13:36:27 EDT 2011

tlwtheq - Thu Jun 16 13:32:10 EDT 2011
Thanks Louie. No errors, but it doesn't do anything either. Ideas?

Object o
for o in current Module do
{
if (o."DXL for setIsLegacy" "" == "True")
{
o."isLegacy" = "true"
}
}// end for o in current Module

Just did a print; never makes it into the if statement.

Re: What's wrong with this picture?
tlwtheq - Thu Jun 16 13:43:00 EDT 2011

tlwtheq - Thu Jun 16 13:36:27 EDT 2011
Just did a print; never makes it into the if statement.

Well, this is an interesting development. I added a print statement
before the if statement. Then it worked. Go figure.

string isDxlLegacyAttr = ""
Object o
for o in current Module do
{
isDxlLegacyAttr = o."DXL for setIsLegacy" ""
print "DXL legacy attribute is set to " isDxlLegacyAttr "\n"
if (isDxlLegacyAttr == "True")

{
o."isLegacy" = "true"
}
}// end for o in current Module

Re: What's wrong with this picture?
tlwtheq - Thu Jun 16 13:51:55 EDT 2011

Not sure why the comment preceding the if statement turned the trick.

Re: What's wrong with this picture?
llandale - Thu Jun 16 15:06:03 EDT 2011

tlwtheq - Thu Jun 16 13:51:55 EDT 2011
Not sure why the comment preceding the if statement turned the trick.

Post the before and the after code

Re: What's wrong with this picture?
tlwtheq - Fri Jun 17 08:11:32 EDT 2011

llandale - Thu Jun 16 15:06:03 EDT 2011
Post the before and the after code

Before:

string isDxlLegacyAttr = ""
Object o
for o in current Module do
{
isDxlLegacyAttr = o."DXL for setIsLegacy" ""

if (isDxlLegacyAttr == "True")

{
o."isLegacy" = "true"
}
}// end for o in current Module

After:

string isDxlLegacyAttr = ""
Object o
for o in current Module do
{
isDxlLegacyAttr = o."DXL for setIsLegacy" ""

print "DXL legacy attribute is set to " isDxlLegacyAttr "\n"

if (isDxlLegacyAttr == "True")

{
o."isLegacy" = "true"
}
}// end for o in current Module


One little print statement can be a big thing.

Re: What's wrong with this picture?
llandale - Fri Jun 17 16:03:14 EDT 2011

tlwtheq - Fri Jun 17 08:11:32 EDT 2011
Before:


string isDxlLegacyAttr = ""
Object o
for o in current Module do
{
isDxlLegacyAttr = o."DXL for setIsLegacy" ""

if (isDxlLegacyAttr == "True")

{
o."isLegacy" = "true"
}
}// end for o in current Module

After:

string isDxlLegacyAttr = ""
Object o
for o in current Module do
{
isDxlLegacyAttr = o."DXL for setIsLegacy" ""

print "DXL legacy attribute is set to " isDxlLegacyAttr "\n"

if (isDxlLegacyAttr == "True")

{
o."isLegacy" = "true"
}
}// end for o in current Module


One little print statement can be a big thing.

Both code as posted works for me. So I guess you are stuck with intuition:

<1> Get rid of the empty line after your "if" statement. If that line is not perfectly empty then its not 'empty' and that line will be the subject of the implied "then" statement, and the bracket block following will always execute.

<2> I'm guessing the "paste" into the Browser is converting some of your invisible characters, typically EOLs and leading spaces. Perhaps some of your End-Of-Line's are not actual EOLs, but rather Carridge-Returns CRs or Line-Feeds LFs. Put your cursor at the end of each line, <del> which should bring the next line up, then hit ENTER to move it back down.

Copy the first code from the browser of your post and try to run it.

  • Louie